
<div id="content-header">
<h1>Manage Permissions</h1>
</div>
<div id="breadcrumb">
<a href="<?php echo $this->Html->url('/admin/')?>" title="Go to Home" class="tip-bottom"><i class="icon-home"></i> List Contents</a>
<a href="#" class="current">Manage Permissions</a>
</div>
<div class="container-fluid">
<div class="row-fluid">
	<div class="span12">
    <?php
    echo $this->element('toolbar');
    ?>	
 <?php echo $this->Form->create('Paginate', array('id' => 'paginate', 'url' => $this->request->here(false), 'type' => 'post', 'inputDefaults' => array('label' => false))); ?>    
             <?php
            $_index = 1;
            ?>		
    <?php foreach ($acos as $aco) : ?>						
		<div class="widget-box">
			<div class="widget-title">
				<span class="icon">
					<i class="icon-th"></i>
				</span>
				<h5><?php echo h($aco['Aco']['model'] ? $aco['Aco']['model'] : $aco['Aco']['alias']); ?></h5>
			</div>
			<div class="widget-content nopadding">
				<table class="table table-bordered table-striped with-check wd-table">
					<thead>
						<tr>
                        	<th>Permission</th>
                        <?php foreach ($roles as $role) : ?>
							<th><?php echo $role?></th>
                        <?php endforeach; ?>
						</tr>
					</thead>
					<tbody>
                       <?php if (empty($aco['children'])): ?>
						<tr>
							<td><?php echo __d('system', 'No Permission action in this module'); ?></td>

						</tr>
                    <?php else: ?>
                    <?php
                        if (empty($aco['children'][0]['children'])) {
                            $aco = array(
                                'children' => array($aco)
                            );
                        }
                        ?>
                        <?php foreach ($aco['children'] as $plugin) : ?>
                        <?php foreach ($plugin['children'] as $child) : ?>
                        <?php $rowName = 'Permission.' .($_index++) . '.'; ?>                
						<tr>
                        <td> <?php
                              echo h($child['Aco']['model'] ? $child['Aco']['model'] : $plugin['Aco']['alias'] . ':' . $child['Aco']['alias']);
                               echo $this->Form->hidden($rowName . 'aco_id', array(
                                'value' => $child['Aco']['id']
                                ));
                            ?>
                        </td>
                        <?php foreach ($roles as $key => $role) : ?>
                        
						<td>                                           
                             <?php
                             
                            $_rowName = $rowName . 'aro.' . $key . '.';
                            if ($key !== $administrator) {
                                $_check = !empty($permission[$child['Aco']['id']][$key]);
                                echo $this->Form->hidden($_rowName . 'role', array(
                                    'value' => $key
                                ));
                                echo $this->Form->input($_rowName . 'set', array(
                                    'type' => 'checkbox',
                                    'checked' => (bool) $_check,
                                    'label' => false,
                                    'value' => 1
                                ));
                            } else {
                                echo $this->Form->input($_rowName . 'set', array(
                                    'type' => 'checkbox',
                                    'checked' => true,
                                    'label' => false,
                                    'value' => 0,
                                    'disabled' => true
                                ));
                            }
                            ?>
                    </td>
                    <?php endforeach; ?>
						</tr>
              <?php endforeach; ?>
            <?php endforeach; ?>              
             <?php endif; ?>
					</tbody>
				</table>							
			</div>
		</div>
<?php endforeach?>


            <?php
            echo $this->Form->hidden('task', array('id' => 'task', 'value' => ''));
            echo $this->Form->end();
            ?>
	</div>	
</div>